! function updateProductForm($) {

    var $form_editor = $('#editor_form');

    // 修改数据
    $('#sort_table').delegate('.editor-trigger', 'click', function () {

        var edit_url = $(this)[0].dataset.href;
        $form_editor.attr( 'action', edit_url.split('/edit').shift() );

        blockElem($form_editor);

        $.ajax({
            method: "GET",
            url: edit_url
        })
            .done(function (data) {

                Object.keys( data ).forEach( function( key ){

                    var input_elem = $form_editor[0][key];

                    if ( ! input_elem || ! isInputElem(key) ) return false;

                    input_elem.value = data[key];

                    if ( input_elem.nodeName === 'SELECT' ) {

                        $(input_elem).val(data[key]).trigger('change');

                    } else if ( input_elem.getAttribute('type').toLowerCase() === 'checkbox') {

                        $(input_elem).removeAttr('value');
                        $(input_elem).prop('checked', data[key]);
                        $.uniform.update();

                    }

                });

                $form_editor.find('.thumbnail').children().attr('src',data['thumb_img']);

                if ( $('#editor_form input[name=sale_end]').val() == '0000-00-00 00:00:00' )
                {
                    $('#editor_form input[name=sale_end]').val('');
                }

            })
            .fail( function () {
                console.log('Failed get temple datas');
            })
            .always( function(){
                unblockElem($form_editor);
            })
    });

    function isInputElem( key ){

        var unfilled_keys = [
            'id' , 'thumb_img'
        ];

        return unfilled_keys.indexOf( key ) === -1;
    }
}(window.jQuery);
